from django.db import models
from django.contrib import admin
from MDC.models import Picture, getImagePath

class VFormat(models.Model):
    vFormat = models.CharField(max_length = 150)

    def __unicode__(self):
        return self.vFormat


class Cartoon(models.Model):
    name = models.CharField(max_length = 150)
    episodeNum = models.IntegerField()
    company = models.CharField(max_length = 150)
    date = models.DateField()
    vFormats = models.ManyToManyField(VFormat)
    path = models.CharField(max_length=256)
    #pics = models.ManyToManyField(Picture)

    def __unicode__(self):
        return self.name

    def getId(self):
        return self.id

    class Meta:
        ordering = ('name',)


class CartoonPicture(models.Model):
    pname = models.CharField(max_length = 1024)
    pic = models.ImageField(upload_to="Cartoon/preview/")
    cartoon = models.ForeignKey(Cartoon)

    def __unicode__(self):
        return self.pic.url

    def getImgUrl(self):
        fp = self.pic
        return fp.url

    def getThumbUrl(self):
        imgUrl = self.getImgUrl()
        thumbUrl = imgUrl.replace("/preview/", "/thumbs/")
        return thumbUrl






    
#admin.site.register(BlogPost)
#admin.site.register(Cartoon, CartoonAdmin)